
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())

# from openai import OpenAI
# client = OpenAI()
# model = "gpt-4o"
from zhipuai import ZhipuAI
client = ZhipuAI()
model = "glm-4v-plus"

def get_completion(messages, model="glm-4v-plus", temperature=0.01):
    response = client.chat.completions.create(
        model=model,
        messages=messages,
        temperature=temperature  
    )
    return response.choices[0].message.content
  
while True:  
    image_url = input("请输入图片URL（输入'exit'退出程序）: ") 
    if image_url is None or image_url == "" :
        continue
    elif image_url.lower() == 'exit':  
        print("程序退出。\n")  
        break  
    user_input = input("请输入提示文字（输入'exit'退出程序）: ")  
    if user_input is None or user_input == "" :
        continue
    elif user_input.lower() == 'exit':  
        print("程序退出。\n")  
        break  
    else :
        messages=[
          {
            "role": "user",
            "content": [
              {
                "type": "image_url",
                "image_url": {
                    "url" : f"{image_url}"
                }
              },
              {
                "type": "text",
                "text": f"{user_input}"
              }
            ]
          }
        ]
        res = get_completion(messages=messages, model=model, temperature=0.7)  
        print("===大语言模型completion：===") 
        print(res)
        print("============END============\n")  
